package com.youku
{
   import flash.display.Sprite;
   import com.youku.interfaces.IPlayerProxy;
   import flash.events.Event;
   import flash.events.MouseEvent;
   import flash.events.KeyboardEvent;
   import com.youku.events.ConductorEvent;
   
   public class UserActionDispatcher extends Sprite
   {
      
      public function UserActionDispatcher() {
         super();
         this._isKeyboardEnable = true;
         this._isMouseEnable = true;
         this._playerProxy = GlobalService.getService(GlobalServiceKeys.PLAYER_PROXY) as IPlayerProxy;
         this._playerProxy.addEventListener(ConductorEvent.STATE_CHANGED,this.onStateChanged);
         this.addEventListener(Event.ADDED_TO_STAGE,this.onAddedToStage);
      }
      
      private var _playerProxy:IPlayerProxy;
      
      private var _isKeyboardEnable:Boolean;
      
      private var _isMouseEnable:Boolean;
      
      private function onAddedToStage(param1:Event) : void {
         removeEventListener(Event.ADDED_TO_STAGE,this.onAddedToStage);
         stage.addEventListener(MouseEvent.MOUSE_MOVE,this.onMouseMove);
         stage.addEventListener(MouseEvent.MOUSE_WHEEL,this.onMouseWheel);
         stage.addEventListener(Event.MOUSE_LEAVE,this.onMouseLeave);
         stage.addEventListener(KeyboardEvent.KEY_DOWN,this.onKeyDown);
      }
      
      public function set keyboardEnable(param1:Boolean) : void {
         this._isKeyboardEnable = param1;
      }
      
      public function set mouseEnable(param1:Boolean) : void {
         this._isMouseEnable = param1;
      }
      
      private function onStateChanged(param1:ConductorEvent) : void {
         var _loc2_:String = param1.data as String;
      }
      
      private function onKeyDown(param1:KeyboardEvent) : void {
         if(!this._isKeyboardEnable)
         {
            return;
         }
         var _loc2_:KeyboardEvent = new KeyboardEvent(param1.type,param1.bubbles,param1.cancelable,param1.charCode,param1.keyCode,param1.keyLocation,param1.ctrlKey,param1.altKey,param1.shiftKey);
         this._playerProxy.dispatchEvent(_loc2_);
      }
      
      private function onMouseLeave(param1:Event) : void {
         var _loc2_:Event = new Event(param1.type,param1.bubbles,param1.cancelable);
         this._playerProxy.dispatchEvent(_loc2_);
      }
      
      private function onMouseWheel(param1:MouseEvent) : void {
         if(!this._isMouseEnable)
         {
            return;
         }
         var _loc2_:MouseEvent = new MouseEvent(param1.type,param1.bubbles,param1.cancelable,param1.localX,param1.localY,param1.relatedObject,param1.ctrlKey,param1.altKey,param1.shiftKey,param1.buttonDown,param1.delta);
         this._playerProxy.dispatchEvent(_loc2_);
      }
      
      private function onMouseMove(param1:MouseEvent) : void {
         if(!this._isMouseEnable)
         {
            return;
         }
         var _loc2_:MouseEvent = new MouseEvent(param1.type,param1.bubbles,param1.cancelable,param1.localX,param1.localY,param1.relatedObject,param1.ctrlKey,param1.altKey,param1.shiftKey,param1.buttonDown,param1.delta);
         this._playerProxy.dispatchEvent(_loc2_);
      }
   }
}
